package march.firstmarch21.march01.plan1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import march.firstmarch21.march01.CallsBean;

import java.net.URI;

public class Driver {
    public static void main(String[] args) {
        Job job;
        Configuration conf = new Configuration();
        try {
            // 获取job
            job = Job.getInstance(conf);

            // 基础配置
            job.setMapperClass(CallsMapper.class);
            job.setReducerClass(CallsReducer.class);
            job.setJarByClass(Driver.class);
            job.setMapOutputKeyClass(CallsBean.class);
            job.setMapOutputValueClass(NullWritable.class);
            job.setOutputKeyClass(CallsBean.class);
            job.setOutputValueClass(NullWritable.class);

            // 配置缓存文件
            URI[] uris = new URI[2];
            uris[0] = new URI("file:///F:/test/test4Input/userPhone.txt");
            uris[1] = new URI("file:///F:/test/test4Input/location.txt");
            job.setCacheFiles(uris);

            // 输入输出文件
            FileInputFormat.setInputPaths(job, new Path("F:\\test\\test4Input\\calls.txt"));
            FileOutputFormat.setOutputPath(job, new Path("F:\\test\\test4Output"));
            boolean b = job.waitForCompletion(true);
            System.exit(b ? 0 : 1);

        } catch (Exception e){
            e.printStackTrace();
        }
    }
}

